home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Tool Chest / Developer Utilities / Installer 4.0.3 SDK / Script Examples / Action Atoms [inaa] Example / atom1.c < prev    next >
Encoding:
Text File  |  1994-11-15  |  4.5 KB  |  153 lines  |  [TEXT/MPS ]

  1. //
  2. //    Atom1.c
  3. //
  4. //        Demonstration of a format1 action atom.
  5. //
  6. //        A dialog is provided that allows the user to select
  7. //        the return value for the action atom. 
  8. //
  9. //        Scriptwriters should be aware that the return values
  10. //        and the actions that they invoke from the installer
  11. //        are different depending on which format of action atom
  12. //        is being used. 
  13. //        
  14. //
  15. //        NOTE: Displaying dialogs from within an action atoms 
  16. //        can enhance or detract from the user experience, and 
  17. //        should be done with consideration to the overall flow
  18. //        of installation. A good rule of thumb is to never display
  19. //        dialogs from an action atom unless absolutely necessary.
  20. //        This example is very useful in demonstrating behavior of
  21. //        the installer in regards to return values from an action
  22. //        atom, but is a terrible example of user interface design.
  23. //
  24. //        mark young • 08/18/94
  25. //
  26. //        Copyright 1993-1994, Apple Computer, Inc., All Rights Reserved
  27. //
  28.  
  29. #include <Traps.h>
  30. #include <Types.h>
  31. #include <dialogs.h>
  32.  
  33. // this line replaces #include "ActionAtomIntf.h" used in Installer 3.x action atoms
  34. #include "ActionAtomHeader.h"
  35.  
  36. // this is needed for highliting the default button in dialog
  37. pascal OSErr SetDialogDefaultItem (    DialogPtr theDialog,
  38.                                     short newItem         ) = {0x303C,0x0304,0xAA68};
  39.  
  40.  
  41. // NOTE: The name of this function 'ActionAtomFormat1' should
  42. // match that specified in the -m option for the line in the
  43. // makefile that compiles this action atom.
  44. pascal long ActionAtomFormat1( AAPBRecPtr atomRecPtr )
  45. {
  46.  
  47.     DialogPtr    theDialog;                        // for dialog
  48.     OSErr        theOSError = 0;                    // for errors
  49.     
  50.     short        theItemHit;                        // gets user response from ModalDialog()
  51.     short        iType;                            // gets control type from GetDItem()
  52.     Handle        iHandle;                        // gets control handle from GetDItem()
  53.     Rect         iRect;                            // gets control rect from GetDItem()
  54.     
  55.     short        currRadioButton = 2;            // current selected radio button
  56.     short        gettingUserResponse = true;        // flag for while loop
  57.     
  58.     short        theStatus = 0;                    // value to return from function
  59.  
  60.     // because we didn't actually use 'the atomRecPtr' in our code
  61.     // the compiler will warn us that the variable wasn't used 
  62.     // - but this line of code will suppress that compiler error
  63.     // - "Aren't you glad you know that ?"
  64.     #pragma unused( atomRecPtr )
  65.     
  66.     // retrieve DLOG/DITL 129 from compiled resource script
  67.     theDialog = GetNewDialog( 129, nil, (WindowPtr) -1 );
  68.  
  69.     // activate OK button when enter or return key is pressed
  70.     theOSError = SetDialogDefaultItem( theDialog, 1 );
  71.  
  72.     // set up the radio button group ( controls 2 - 4 )
  73.     GetDItem( theDialog, 2, &iType, &iHandle, &iRect);
  74.     SetCtlValue( (ControlHandle) iHandle, 1 );    
  75.     
  76.     GetDItem( theDialog, 3, &iType, &iHandle, &iRect);
  77.     SetCtlValue( (ControlHandle) iHandle, 0 );    
  78.     
  79.     GetDItem( theDialog, 4, &iType, &iHandle, &iRect);
  80.     SetCtlValue(  (ControlHandle) iHandle, 0 );    
  81.     
  82.     // select the new dialog
  83.     SelectWindow( (WindowPtr) theDialog );
  84.     
  85.     // show the new dialog
  86.     ShowWindow( (WindowPtr) theDialog );
  87.     
  88.     // keep getting response from user until
  89.     // the OK is activated in the new dialog
  90.     gettingUserResponse = true;
  91.     while ( gettingUserResponse )
  92.         {
  93.         // get user selection from the new dialog
  94.         ModalDialog( nil, &theItemHit );
  95.         
  96.         switch ( theItemHit )
  97.             {
  98.             // first control is the OK key
  99.             case( 1 ) : 
  100.                         // exit loop
  101.                         gettingUserResponse = false;
  102.                         break;
  103.                         
  104.             // all other controls in dialog are radio buttons
  105.             default :     
  106.                         // continue with loop
  107.                         gettingUserResponse = true;
  108.                         
  109.                         // if the radio button selection changed
  110.                         if ( currRadioButton != theItemHit )
  111.                             {
  112.                             // turn previous radio button off
  113.                             GetDItem( theDialog, currRadioButton, &iType, &iHandle, &iRect);
  114.                             SetCtlValue(  (ControlHandle) iHandle, 0 );    
  115.         
  116.                             // turn current radio button on
  117.                             GetDItem( theDialog, theItemHit, &iType, &iHandle, &iRect);
  118.                             SetCtlValue(  (ControlHandle) iHandle, 1 );    
  119.         
  120.                             // save current radio button choice
  121.                             currRadioButton = theItemHit;
  122.                             }
  123.                         break;
  124.             }// switch
  125.  
  126.         }// while
  127.         
  128.     // get rid of the new dialog
  129.     DisposDialog( theDialog );
  130.  
  131.     // select a value to return from this function according to
  132.     // which radio button was selected in the dialog
  133.     switch ( currRadioButton )
  134.         {
  135.         // return 0
  136.         case( 2 ) : theStatus = 0;        // user selected return 0
  137.                     break;
  138.                     
  139.         // return 1
  140.         case( 3 ) : theStatus = 1;        // user selected return 1
  141.                     break;
  142.                     
  143.         // return -1
  144.         case( 4 ) : theStatus = -1;        // user selected return -1
  145.                     break;
  146.         }
  147.         
  148.     // return value selected by user in dialog
  149.     return( theStatus );
  150.  
  151. }
  152.  
  153.